Try the following one line script examples to familiarize yourself with entering and running scripts in a text window.
• Make a new text window ("File" menu, shortcut N).
• Enter 3 + 4 into the window, as shown below, and press the Enter key (in the numeric keypad). If your keyboard has no Enter key, use the combination ctrl-C instead.
3+4
7
• The answer (7 in this case) is referred to as the "result."
• Now place the cursor anywhere in the first script line, or select all (not part) of this first line. Press the Enter key once more and the result will again be displayed.
This illustrates a very basic property of the Smile text window. Smile executes only the line (or lines) which is selected or the line where the cursor is positioned.
Multi-Line Script Example
Starting with a blank text window, enter the following three line script and do not yet press the Enter key.
----------------------------
set myNum to 3 + 4
set yourNum to 1 + 9
set total to myNum + yourNum
----------------------------
Verify for yourself that the result from running the above script varies depending on the position of the cursor on pressing the Enter key.
Select each line, or position the cursor in a particular line, and press the Enter key. Then select all three lines and press the Enter key. Try to predict the result, and check the actual result against your prediction.
Note that you can run the script line by line : this is because the variables are persistent.
Also, try the following with the above script. Type the following after the last line and press the Enter key.
----------------------------
myNum
----------------------------
The result (7) will be displayed which is the value that the variable "myNum" evaluates to in line one of the script. You could also enter "yourNum" and "total" on the last line, to evaluate those variables on pressing the Enter key. This provides a powerful tool to display the value of variables used in the expressions of your script.